package com.job.common.util;


import cn.hutool.crypto.digest.BCrypt;

public class MiUtil {

    public static String encryptPassword(String password) {
        // 生成一个新的盐值
        String salt = BCrypt.gensalt();
        System.out.println(salt);

        // 生成散列密码
        String hashedPassword = BCrypt.hashpw(password, salt);
        return hashedPassword;
    }

    public static boolean checkPassword(String password, String storedHash) {
        // 验证密码
        return BCrypt.checkpw(password, storedHash);
    }

    public static void main(String[] args) {
        String password = "123456";
        String hashedPassword = encryptPassword(password);
        System.out.println(hashedPassword);
        System.out.println(checkPassword("123457", hashedPassword));
//        System.out.println(checkPassword("123456", "$2a$10$bM1oiEKCfcNXFUlEWmdiAu9lwRgz3jO1fV0C8yJ1KeydwbBsdUreO"));

    }

}
